package com.itheima.mapper;

import com.itheima.pojo.PurchaseHistory;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface PurchaseHistoryMapper {
    // 添加购买记录
    @Update("insert into purchase_history values(null,#{itemId},#{buyerId},#{sellerId})")
    @ResultMap("purchaseHistoryResultMap")
    void add(@Param("itemId") Integer itemId, @Param("buyerId") Integer buyerId, @Param("sellerId") Integer sellerId);

    // 根据卖家id选择
    @Select("select * from purchase_history where seller_id = #{sellerId}")
    @ResultMap("purchaseHistoryResultMap")
    List<PurchaseHistory> selectBySellerId(Integer sellerId);

    // 根据买家id选择
    @Select("select * from purchase_history where buyer_id = #{buyerId}")
    @ResultMap("purchaseHistoryResultMap")
    List<PurchaseHistory> selectByBuyerId(Integer buyerId);
}
